#!/bin/bash
OS=$(cat /etc/issue|cut -f 1 -d ' ')
case $OS in
    'Arch')    INSTALL() { sudo pacman -S $@; }                                        ;;
    'Ubuntu')  INSTALL() { sudo apt install $@ -y --allow-unauthenticated; }                 ;;
    *)         echo 'Your distribution has not implementd yet, please modify this command'   ;;
esac
CONF_PATH=~/.config/fish/conf.d/charles.fish
if [[ ! -d ~/.config/fish/conf.d ]]; then
    mkdir -p ~/.config/fish/conf.d
fi
mkdir -p ~/.cabal/bin
echo '# This is the Charles Scripts Configuration.'|tee $CONF_PATH
echo 'set -g CHARLES_HOME ~/.local/share/CharlesScripts/charles' |tee -a $CONF_PATH
echo 'set -g CHARLES_BACKUP ~/.config/CharlesBackup' |tee -a $CONF_PATH


ANACONDA_PATH=$(locate anaconda3|grep -E 'anaconda3/bin$'|grep $USER||true)
if [ ! -z "$ANACONDA_PATH" ];then
    echo set -x PATH $ANACONDA_PATH \$PATH|tee -a $CONF_PATH
else
    echo 'There is no anaconda found!'
    echo 'You should manually add anaconda path to the fish config file. i. e.:'
    echo 'set -x PATH \$ANACONDA_PATH \$PATH'
    read -p 'press Enter to continue:'
fi

if [ `which autojump|wc -l` == 0 ];then INSTALL autojump;fi
echo "source /usr/share/autojump/autojump.fish" |tee -a $CONF_PATH

echo "source \$CHARLES_HOME/shell.rc.d/init.fish" |tee -a $CONF_PATH

echo "source \$HOME/.config/fish/conf.d/*" |tee -a $HOME/.config/fish/config.fish

#ABBRS
fish -c "abbr ... 'cd ../..'"
fish -c "abbr autoremove 'pacman -Qtdq|xargs sudo pacman -Rsn --noconfirm'"
fish -c "abbr c 'clear; cd'"
fish -c "abbr cl 'cd ..;ls'"
fish -c "abbr du. 'du . --max-depth 1 -h'"
fish -c "abbr eg 'grep -E'"
fish -c "abbr emacsc 'emacs --no-window-system'"
fish -c "abbr ftps 'python3 -m http.server 8080'"
fish -c "abbr gaa 'git add -A'"
fish -c "abbr gb 'git branch -c'"
fish -c "abbr gck 'git checkout'"
fish -c "abbr gcm 'git commit -m'"
fish -c "abbr gl 'git l'"
fish -c "abbr gm 'git merge --no-ff'"
fish -c "abbr gp 'git push'"
fish -c "abbr gpl 'git pull'"
fish -c "abbr gst 'git status'"
fish -c "abbr histg 'history | grep'"
fish -c "abbr i 'ipython'  # '--no-confirm-exit --no-banner --pprint -i'"
fish -c "abbr l 'ls'"
fish -c "abbr la 'ls -a'"
fish -c "abbr le 'ls|egrep'"
fish -c "abbr lf 'ls -lah --full-time'"
fish -c "abbr lg 'ls|grep'"
fish -c "abbr ll 'ls -lah'"
fish -c "abbr mag2torrent 'aria2c --bt-metadata-only=true --bt-save-metadata=true'"
fish -c "abbr n 'xdg-open .'"
fish -c "abbr o 'xdg-open'"
fish -c "abbr p 'python'"
fish -c "abbr pdb 'python -mpowerline.bindings.pdb'"
fish -c "abbr tmux 'tmux -2'"
fish -c "abbr su 'sudo su'"

case $OS in
    'Ubuntu') fish -c "abbr u 'apt-upgrade'";;
    'Arch') fish -c "abbr u 'pacman -Syu;pacman -Rs (pacman -Qtdq)'";;
esac

